
<template>
  <Layout :style="{background: '#fff'}">
    <Sider :style="{background: '#fff',borderRight:'1px solid #eee'}"
           :width="300">
      <Card icon="ios-options"
            :bordered="false">
        <p slot="title">日历</p>
        <a slot="extra">
          <Checkbox v-model="showTitle">显示</Checkbox>
        </a>

        <div class="li"
             v-for="(li, i) in days"
             :key="i"
             @click="load(i)">
          <span class="day">{{li.day}}</span>
          <p v-show="showTitle">
            {{li.title}}
          </p>
        </div>
      </Card>
    </Sider>
    <Content :style="{padding:'10px 20px'}">
      <div class="btns">
        <Button type="primary"
                @click="add()">记录</Button>
      </div>
      <h3>{{day.title}} </h3>
      <div class="items">
        <div class="item"
             v-for="(item,i) in day.items"
             :key="i">
          <Tooltip :content="item.name">
            <Icon :type="item.icon"
                  size="96"
                  :class="{cur:item.integral>0}" />
            <div class="rate">
              <Rate v-model="item.integral"
                    disabled />
            </div>
          </Tooltip>
        </div>
      </div>
      <p>
        {{day.note}}
      </p>
      <div>
        <div class="demo-upload-list"
             v-for="(item,v) in day.pics"
             :key="v">
          <img :src="serveUrl+item.url">
          <div class="demo-upload-list-cover">
            <Icon type="ios-eye-outline"
                  @click.native="handleView(v)"></Icon>
          </div>
          <Modal :title="file.name"
                 v-model="visible">
            <img :src="serveUrl+file.url"
                 v-if="visible"
                 style="width: 100%">
          </Modal>
        </div>
      </div>
    </Content>
  </Layout>
</template>
<script>
export default {
  data () {
    return {
      serveUrl: 'http://localhost:21021/',
      showTitle: true,
      days: [],
      check: true,
      page: 1,
      day: {},
      file: {},
      visible: false
    }
  },
  created () {
    this.init(this.page)
  },
  methods: {
    init (page) {
      var action = "/api/services/app/DailyLife/GetPaged"
      this.$http.get(action, { page: page }).then(r => {
        this.days = r.result.items
        if (this.page == 1 && this.days.length > 0) {
          this.load(0)
        }
      })
    },
    load (i) {
      this.$http.get("/api/services/app/DailyLife/GetByKey?id=" + this.days[i].id).then(r => {
        this.day = r.result
      })
    },
    add () {
      this.$router.replace('/health/add')
    },
    handleView (i) {
      this.file = this.day.pics[i];
      this.visible = true;
    },
  }
}
</script>
<style scoped>
.item {
  text-align: center;
  margin: 20px;
  display: inline-block;
  height: 150px;
  width: 150px;
  vertical-align: top;
}
.ivu-icon {
  color: #f7f7f7;
}
.item:hover .ivu-icon {
  color: #2d8cf0;
}
.cur {
  color: #2d8cf0;
}
.item {
  display: inline-block;
  width: 200px;
  position: relative;
  margin: 0 10px 0 0;
}
.item .delete {
  background: #999;
  color: white;
  position: absolute;
  bottom: 0;
  width: 100%;
  line-height: 28px;
  display: none;
  z-index: 999;
}
.item:hover .delete {
  display: block;
}
.item img {
  width: 200px;
  border: 1px solid #ddd;
}
.delete:hover {
  background: red;
}
.upload {
  display: inline-block;
  min-width: 200px;
}
.demo-upload-list {
  display: inline-block;
  width: 60px;
  height: 60px;
  text-align: center;
  line-height: 60px;
  border: 1px solid transparent;
  border-radius: 4px;
  overflow: hidden;
  background: #fff;
  position: relative;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
  margin-right: 4px;
}
.demo-upload-list img {
  width: 100%;
  height: 100%;
}
.demo-upload-list-cover {
  display: none;
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.6);
}
.demo-upload-list:hover .demo-upload-list-cover {
  display: block;
}
.demo-upload-list-cover i {
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  margin: 0 2px;
}
.li {
  cursor: pointer;
  margin-bottom: 5px;
  border-bottom: 1px dotted #eee;
  padding: 0 5px;
  border-radius: 5px;
}
.li:hover {
  background: #f7f7f7;
}
.li p {
  font-size: 12px;
  color: #999;
  margin-bottom: 5px;
}
.day {
  font-weight: bold;
  line-height: 26px;
}
h3 {
  padding: 10px 0;
}
.btns {
  text-align: right;
  padding: 0 10px 5px 0;
  border-bottom: 1px dotted #eee;
}
</style>